package sanrenxing.dayEnd.backRepertoryTotal.dao;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import sanrenxing.dayEnd.backRepertoryTotal.domain.BoundCountExtrat;
import sanrenxing.dayEnd.backRepertoryTotal.domain.CashAccount;
import sanrenxing.dayEnd.backRepertoryTotal.domain.CashCountExtrat;
import sanrenxing.dayEnd.backRepertoryTotal.domain.ManagerMoney;

import java.util.List;

/**
 * 用于收益计提的dao
 */
public interface EarningCountDao {

    /**
     * 查询现金收益计提信息:从存款业务
     * @return
     */
    @Select("select * from (select rownum rn,ca.bankName as bankName,ca.bankCard as bankCard,db.depMoney as money,ca.cardRate as accId," +
            "db.businType as businTime,sysdate as dates,round(to_number(db.expiryDate-db.businTime)) as intePer,0 as MoneyInterest from " +
            "depositBusiness db  join cashAccount ca on db.caIds=ca.caId where db.handif=1) ss where rn between #{start} and #{end}")
    public List<CashCountExtrat> queryCashDeposit(@Param("start") int start, @Param("end") int end);

    /**
     * 查询现金收益计提信息:从现金库存
     * @return
     */
    @Select("select * from (select rownum rn,ca.bankName,ca.bankCard,cs.caMoney as money,ca.cardRate as accId,2 as businTime,sysdate as dates,365 as intePer,0 as MoneyInterest " +
            "from cashStock cs join cashAccount ca on cs.caId=ca.caId) ss where rn between #{start} and #{end}")
    public List<CashCountExtrat> queryCashCountToStock(@Param("start") int start, @Param("end") int end);


    /**
     * 查询收益计提存款利息行数
     * @return
     */
    @Select("select count(*) from depositBusiness db  join cashAccount ca on db.caId=ca.caId")
    public int cashCount();

    /**
     * 查询收益计提现金库存利息行数
     * @return
     */
    @Select("select count(*) from cashStock cs join cashAccount ca on cs.caId=ca.caId")
    public int cashStockCount();

    /**
     * 查询债券收益计提
     * @return
     */
    @Select("select * from (select rownum rn,si.bondName as bondName,si.bondId as bondId,si.coupRate as coupRate,ss.secNum as bondIdCount," +
            "si.bondType as bondType,sysdate as dates,si.beginInte as coupNum,si.endInte as businDate,0 as bondInterest from " +
            "securitiesStock ss join securitiesInformation si on ss.seId=si.bondId where si.endInte>sysdate-1) ss where rn between #{start} and #{end}")
    public List<BoundCountExtrat> queryBound(@Param("start") int start, @Param("end") int end);

    /**
     * 债券收益计提行数
     * @return
     */
    @Select("select count(*) from securitiesStock ss join securitiesInformation si on ss.seId=si.bondId  where si.endInte>sysdate-1")
    public int bondCount();

    /**
     *收益计提的托管费
     */
    @Select("select fs.fundName as ,fs.fundId as ,fs.fundSize as fundNet,ts.custoRate as rate,1 as raType," +
            "sysdate as businDate,fs.caId as caName from " +
            "fundSetup fs join trusteeSetup ts on fs.custoId=ts.custoId")
    public ManagerMoney custoIdQuery();

    /**
     * 收益计提的管理费
     * @return
     */
    @Select("select fs.fundName as ,fs.fundId as ,fs.fundSize as fundNet,ms.adminRate as rate,2 as raType," +
            "sysdate as businDate,fs.caId as caName  from fundSetup fs join managerSetup ms on fs.adminId=ms.adminId")
    public ManagerMoney adminIdQuery();

    /**
     * 判断昨天是否有资产净值，如果有则取出
     * @return
     */
    @Select("select netAsset from worthStatistics where netDate=(select max(netDate) from worthStatistics)")
    public Double yesterdayMoneyValue();

    /**
     * 债券利息收益计提点击统计
     */
    @Select("call add_EarningCount(#{days})")
    public void bondAlipay(@Param("days") int days);

    /**
     * 现金利息收益计提点击统计
     */
    @Select("call add_Cash_pro(#{days})")
    public void cashAlipay(@Param("days") int days);

    /**
     * 两费付出收益计提点击统计
     */
    @Select("call add_adCu_pro(#{money})")
    public void adCuAlipay(double money);

    /**
     * 为了显示现金账户名称
     * @return
     */
    @Select("select * from CashAccount")
    public List<CashAccount> queryCashAccount();
}
